module.factory('autocompleteService', [
		'$rootScope',
		'$http',
		function($rootScope, $http) {
			var instance = {
				init : function(divName, list, addFunction) {
					divName.autocomplete({
						minLength : 1,
						source : function(request, response) {
							var results = $.ui.autocomplete.filter(list,
									request.term);
							response(results.slice(0, 10));
						},
						autoFocus: true,
						focus : function(event, ui) {
							// divName.val(ui.item.name);
							return false;
						},
						select : function(event, ui) {
							divName.val(ui.item.name);
							if(addFunction != null) {
								addFunction(ui.item);
							}
							return false;
						},
						response : function(event, ui) {
						}
					}).data("autocomplete")._renderItem = function(ul, item) {
						return $("<li></li>").data("item.autocomplete", item)
								.append("<a><span style='font-size: small;''>" + item.name + "</span></a>")
								.appendTo(ul);
					};
				}
			};
			return instance;
		} ]);